package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 操作模块枚举，用于短信日志记录
 * @author youli.chen
 */
@Getter
public enum SmsModuleTypeEnum {

    CUSTOMER(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "enum.smsModuleType.name.customer", "customer"),
    CONTACT(XbbRefTypeEnum.CONTACT.getCode(),"enum.smsModuleType.name.contact","contact"),
    WORK_ORDER(XbbRefTypeEnum.WORK_ORDER.getCode(),"enum.smsModuleType.name.work_order","workOrder"),
    CLUE(XbbRefTypeEnum.CLUE.getCode(),"enum.smsModuleType.name.clue","clue"),
    WORK_ORDER_V2(XbbRefTypeEnum.WORK_ORDER_V2.getCode(),"enum.smsModuleType.name.work_order_v2",XbbRefTypeEnum.WORK_ORDER_V2.getAlias()),

    UNKNOWN(XbbRefTypeEnum.UNKNOWN.getCode(), "enum.smsModuleType.name.unknown", "unknown"),
    ;

    /** 枚举值 -- 模块类型标识*/
    private final int code;

    /** 枚举信息--模块名称*/
    private final String name;

    /** 枚举描述 --*/
    private final String alias;

    /**
     * 构造一个<code>SubModuleEnum</code>枚举对象
     *
     * @param code
     * @param name
     * @param alias
     */
    SmsModuleTypeEnum(int code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 通过枚举<code>alias</code>获得枚举
     *
     * @param alias
     * @return OperateModuleTypeEnum
     */
    public static SmsModuleTypeEnum getByAlias(String alias) {
        for (SmsModuleTypeEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code
     * @return OperateModuleTypeEnum
     */
    public static SmsModuleTypeEnum getByCode(Integer code) {
        for (SmsModuleTypeEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<OperateModuleTypeEnum>
     */
    public static List<SmsModuleTypeEnum> getAllEnum() {
        List<SmsModuleTypeEnum> list = new ArrayList<>();
        for (SmsModuleTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (SmsModuleTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

}
